﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title></title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <style type="text/css">
    </style>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <form id="formSet">
        <div class="fieldset1 tabel_col clearFix">
            <div class="sqPanel">
                <div class="sqPanel_head inL">
                    <div class="btnsBox inLC" id="chooseCstBtnDiv">
                        <%--<span id="refreshBtn" class="sq-button sq-button-round">刷新</span>--%>
                        <span id="chooseCstBtn" class="sq-button sq-button-round">选择客户</span>
                    </div>
                    <span>基本信息</span>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">客户</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" readonly="readonly" class="ui-textbox"
                               value="${data.cstNm}" validate="{required:true}">
                        <input name="cstId" id="cstId" type="hidden" value="${data.cstId}" validate="{required:true}">
                        <input name="cstTypCd" id="cstTypCd" type="hidden" value="${cstTypCd}" validate="{required:true}">
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">项目类型</div>
                    <div class="field">
                        <select name="prjTypCd" id="prjTypCd" onchange="checkCstRisk(0)">
                            <option value="CTYW" <c:if test="${data.prjTypCd eq 'CTYW'}">selected</c:if>>传统业务</option>
                            <option value="CPYW" <c:if test="${(empty data) or (data.prjTypCd eq 'CPYW')}">selected</c:if>>城配业务</option>
                            <option value="CDDYWUL" <c:if test="${data.prjTypCd eq 'CDDYWUL'}">selected</c:if>>车抵贷业务(线下)</option>
                            <option value="ESCJYD" <c:if test="${data.prjTypCd eq 'ESCJYD'}">selected</c:if>>二手车交易贷</option>
                            <option value="OWNJYD" <c:if test="${data.prjTypCd eq 'OWNJYD'}">selected</c:if>>内转交易贷</option>
                        </select>
                    </div>
                </div>
                <div class="fieldBox col_33" id="isFarmerDiv">
                    <div class="label">是否农民</div>
                    <div class="field">
                        <select name="isFarmer" id="isFarmer">
                            <option value="0" <c:if test="${data.isFarmer eq '0'}">selected</c:if>>否</option>
                            <option value="1" <c:if test="${data.isFarmer eq '1'}">selected</c:if>>是</option>
                        </select>
                    </div>
                </div>
                <div class="fieldBox col_33" id="isBigCstWorkDiv" style = "display:none">
                    <div class="label">是否大客户业务</div>
                    <div class="field">
                        <select name="isBigCstWork" id="isBigCstWork">
                            <option value="1" <c:if test="${data.isBigCstWork eq '1'}">selected</c:if>>是</option>
                            <option value="0" <c:if test="${data.isBigCstWork eq '0'}">selected</c:if>>否</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="fieldset1 tabel_col clearFix">
            <div class="sqPanel">
                <div class="sqPanel_head inL">
                    <div class="btnsBox inLC" id="addBtnDiv">
                        <%--<span id="refreshBtn" class="sq-button sq-button-round">刷新</span>--%>
                        <span id="addBtn" class="sq-button sq-button-round">新增</span>
                        <span id="addGuacheBtn" class="sq-button sq-button-round">新增挂车</span>
                        <span id="deletelBtn" class="sq-button sq-button-round">删除</span>
                        <span id="copyBtn" class="sq-button sq-button-round">复制</span>
                    </div>
                    <span style="text-align: center;dispay:inline-block;margin-left:35%;">设备信息</span>
                    <div style="float:right;margin-right:0.5%">
                        <span style="color:red;font-size: smaller">系统自动计算调节费后，将自动将调节费累加至设备款和首期中，如对调节费有异议，可删除设备重新报价</span>
                    </div>
                </div>
                <div class="sqPanel_body">
                    <div id="grid_chanpin" class="sq-grid"></div>
                    <div id="grid_ershouche" class="sq-grid" style="display: none"></div>
                </div>
            </div>
        </div>
        <div class="fieldset1 tabel_col clearFix">
            <div class="caption">
                <span class="title">报价信息</span>
            </div>
            <div class="fieldBox col_33">
                <div class="label">合同总额(元)</div>
                <div class="field">
                    <input name="contAmt" id="contAmt" type="text" readonly="readonly" class="ui-textbox" value="${data.contAmt}" validate="{required:true}" contenteditable="false">
                </div>
            </div>
            <div class="fieldBox col_33" id="isBpDiv">
                <div class="label">是否包牌</div>
                <div class="field">
                    <select name="isBp" id="isBp" data-value="" validate="{required:true, select: true}" ligerui="{width: 100}">
                        <c:forEach items="${isBpList}" var="kv">
                            <option value="${kv.key}" <c:if test="${kv.key eq data.isBp}">selected</c:if>>${kv.value}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">租赁期数</div>
                <div class="field">
                    <input name="lsPd" id="lsPd" type="number" class="ui-textbox" value="${data.lsPd}" validate="{required:true}" ligerui="{width: 60}">
                    <select name="lsPdUntCd" id="lsPdUntCd" type="select" class="ui-textbox" value="${data.lsPdUntCd}" validate="{required:true}" ligerui="{width: 60}">
                        <option value="1" <c:if test="${data.lsPdUntCd eq '1'}">selected</c:if>>月</option>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">租赁年利率（%）</div>
                <div class="field">
                    <input name="annIntRatePct" id="annIntRatePct" type="number" class="ui-textbox" value="${data.annIntRatePct}" validate="{required:true}">
                </div>
            </div>
            <div class="fieldBox col_33" id="isSplMfrDiv">
                <div class="label">是否厂商业务</div>
                <div class="field">
                    <select name="isSplMfr" id="isSplMfr" data-value="" validate="{required:true, select: true}" ligerui="{width: 60}">
                        <option value="0" <c:if test="${data.isSplMfr eq '0'}">selected</c:if>>否</option>
                        <option value="1" <c:if test="${data.isSplMfr eq '1'}">selected</c:if>>是</option>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_33" id="isPreIntDiv">
                <div class="label">是否有前置利息</div>
                <div class="field">
                    <select name="isPreInt" id="isPreInt" data-value="" validate="{required:true, select: true}" ligerui="{width: 60}">
                        <option value="0" <c:if test="${data.isPreInt eq '0'}">selected</c:if>>否</option>
                        <option value="1" <c:if test="${data.isPreInt eq '1'}">selected</c:if>>是</option>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_33" id="payWayCdDiv">
                <div class="label">还款方式</div>
                <div class="field">
                    <select name="payWayCd" id="payWayCd" data-value="" validate="{required:true, select: true}" ligerui="{width: 100}">
                        <option value="4" <c:if test="${data.payWayCd eq '4'}">selected</c:if>>期末等额本息</option>
                        <option value="9" <c:if test="${data.payWayCd eq '9'}">selected</c:if>>阶梯还款</option>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_33" id="isVisitDiv">
                <div class="label">家访费</div>
                <div class="field">
                    <select id="isVisit" name="isVisit" data-value="" validate="{required:true, select: true}" ligerui="{width: 60}">
                        <option value="0" <c:if test="${data.isVisit eq '0'}">selected</c:if>>无</option>
                        <option value="1" <c:if test="${data.isVisit eq '1'}">selected</c:if>>有</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="fieldset1 tabel_col clearFix">
            <div class="caption">
                <span class="title">上牌信息</span>
            </div>
            <div class="fieldBox col_33">
                <div class="label">上牌城市</div>
                <div class="field">
                    <jsp:include page="../../system/sysRegion/region.jsp" flush="true">
                        <jsp:param name="regionShowLvl"  value="2"/>
                    </jsp:include>
                </div>
            </div>
            <div class="fieldBox col_33" id="isLicDiv">
                <div class="label">是否已上牌</div>
                <div class="field">
                    <select name="isLic" id="isLic" data-value="" validate="{required:true, select: true}" ligerui="{width: 60}" onchange="setLicDtShow()">
                        <option value="0" <c:if test="${data.isLic eq '0'}">selected</c:if>>否</option>
                        <option value="1" <c:if test="${data.isLic eq '1'}">selected</c:if>>是</option>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_33" id = "licDtdiv" style="display: none">
                <div class="label">上牌时间</div>
                <div class="field">
                    <input name="licDt" id="licDt" type="text" class="ui-datepicker" value="${data.licDt}">
                </div>
            </div>
            <div class="fieldBox col_33" id="licAgainDiv" style="display: none">
                <div class="label">是否再次上牌</div>
                <div class="field">
                    <select name="isLicAgain" id="isLicAgain" value="${data.isLicAgain}" validate="{required:true, select: true}" ligerui="{width: 60}" onchange="setLicAgainDtShow()">
                        <option value="0" <c:if test="${data.isLicAgain eq '0'}">selected</c:if>>否</option>
                        <option value="1" <c:if test="${data.isLicAgain eq '1'}">selected</c:if>>是</option>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_33" id = "licAgainDtdiv" style="display: none">
                <div class="label">再次上牌时间</div>
                <div class="field">
                    <input name="licAgainDt" id="licAgainDt" type="text" class="ui-datepicker" value="${data.licAgainDt}">
                </div>
            </div>
        </div>
        <div class="fieldset1 tabel_col clearFix" <c:if test="${editFlag}">style="display: none"</c:if>>
            <div class="sqPanel">
                <div class="sqPanel_head inL">
                    <span>筛选结果</span>
                </div>
                <div class="sqPanel_body">
                    <div id="grid_route_result" class="sq-grid" style="display: none"></div>
                    <div id="route_result_tip"
                         style="text-align: center;height: 60px;line-height: 60px;background:#F0F0F0;display: none;">
                        <span>合规机构筛选中,请稍后再次查询</span>
                    </div>
                </div>
            </div>
        </div>
        <div class="btnsBox">
            <div id="filterBtn" onclick="showTips()" class="sq-button sq-button-round" <c:if test="${not editFlag}">style="display: none"</c:if>>筛选</div>
            <%--<div id="viewResult" onclick="showRouteResult()" class="sq-button sq-button-round" <c:if test="${editFlag}">style="display: none"</c:if>>查看筛选结果</div>--%>
        </div>
        <div id="chooseVechDiv" class="searchArea" style="display: none">
            <div class="fieldset1 clearFix">
                <div class="fieldBox" >
                    <div class="label">车源编号</div>
                    <div class="field">
                        <input name="carNo" id="carNo" type="text"   class="ui-textbox" value="">
                    </div>
                </div>

                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-round" onclick="searchBtn()">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round" onclick="clearBtn()">清空</span>
                    <span id="detailBtn" class="sq-button sq-button-round" onclick="detailBtn()">确定</span>
                </div>
            </div>
            <div id="chooseVech"></div>
        </div>
    </form>
    <script type="text/javascript">
        var prdTypKVList = ${prdTypKVList};
        var comboBoxeList = ${comboBoxeList}; // 品牌列表
        var comboBoxeData = {}; // 产品品牌
        comboBoxeData["Rows"] = comboBoxeList;
        comboBoxeData["Total"] = comboBoxeList.length;
        var yesOrNoCdList = ${yesOrNoCdList};
        var bankNoTypCdList = ${bankNoTypCdList} ;
        var editFlag = '${editFlag}'=='true'?'true':'false';
        var checkVal = '';
        var routeId = '${data.id}';
        var initFeeVos = ${preRoutePrpsFeeVOS} ;
        var prjTypCdFlag ;
        var vehSrcListGrid ; // 二手车车源列表
        var provinceKVList = ${provinceKVList} ;
        <c:if test="${not empty preRoutePrpsFeeVOS}">
            initFeeVos = ${preRoutePrpsFeeVOS};
            for(index in initFeeVos){
                initFeeVos[index].feePct = '';
                initFeeVos[index].feeAmt = '';
            }
        </c:if>
        var calBaseCdListJSON = [];
        <c:if test="${not empty calBaseCdList}"> calBaseCdListJSON = ${calBaseCdList}; </c:if>
        var ligerGrid_chanpin;  // 新车设备表
        var ligerGrid_esc ; // 二手车设备列表
        var liger_route_result ; // 预筛选结果
        var rowindex ; // 二手车添加车源的行号
        var selectFlag = true;
        $(function () {
            $("#formSet").ligerForm({
                validate: true
            });
            changeTable();
            // ----------------------选择客户---------------------------
            $("#chooseCstBtn").click(function () {
                var cstRlFlag = ProjectConstant.CST_RL_CST;//客户
                var addPrjPage = "1";
                $.ligerDialog.open({
                    title: '选择客户',
                    height: 500,
                    width: 850,
                    url: '<%=path%>/preinsroute/preRouteBscInfo/toChooseCstPage.do?cstRlFlag=' + cstRlFlag + '&&addPrjPage=' + addPrjPage
                });
            });
            // --------------------添加设备--------------------------------------
            // 新增主车
            $('#addBtn').on('click', function (event) {
                event.preventDefault();
                if(getIsSecond($("#prjTypCd").val())){
                    addEsc(ligerGrid_esc.rows.length-1);
                }else{
                    ligerGrid_chanpin.addRow({
                        id:'', // 后端生成
                        brId:'',
                        brCd:'',
                        modelId:'',
                        modelNm:'',
                        prdNm:'',
                        prdId:'',
                        guidePc:0,
                        prdQty:1,
                        prdTypCd:'', // 用途cd
                        mainTic:0,
                        reTic:0,
                        isCheckOut:0,
                        checkOutDt:'',
                        routeId:routeId,
                        preRoutePrpsFeeVOS:initFeeVos
                    });
                    ligerGrid_chanpin.extendDetailAll();
                }
            });

            // 新增挂车
            $('#addGuacheBtn').on('click', function (event) {
                event.preventDefault();
                ligerGrid_chanpin.addRow({
                    id:'', // 后端生成
                    brId:'',
                    brCd:'',
                    modelId:'',
                    modelNm:'',
                    prdNm:'',
                    prdId:'',
                    guidePc:0,
                    prdQty:1,
                    prdTypCd:'2',
                    mainTic:0,
                    reTic:0,
                    isCheckOut:0,
                    checkOutDt:'',
                    routeId:routeId,
                    preRoutePrpsFeeVOS:initFeeVos
                });
                ligerGrid_chanpin.extendDetailAll();
            });
            // 生成设备信息
            if (getIsSecond($("#prjTypCd").val())){
                ligerGrid_escload(editFlag);
            } else{
                ligerGrid_chanpinload(editFlag);
            }
            // --------------------------删除设备--------------------------------------------
            $('#deletelBtn').on('click', function(event) {
                if (getIsSecond($("#prjTypCd").val())){
                    event.preventDefault();
                    var selectedRows = ligerGrid_esc.getSelectedRows();
                    if(selectedRows.length == 0){
                        top.$.ligerDialog.SQalert({content: "请选中要删除的数据", SQ_type: "warning"});
                        return false; //验证不通过，不执行以下代码
                    }
                    for(var i=0;i<selectedRows.length;i++){
                        ligerGrid_esc.deleteRow(selectedRows[i]);
                    }
                    ligerGrid_esc.extendDetailAll();
                    var totalContAmt = 0 ;
                    for (var j=0;j<ligerGrid_esc.getData().length;j++){
                        totalContAmt += ligerGrid_esc.getData()[j].vehAmt ;
                    }
                    $("#contAmt").val(totalContAmt) ;
                } else{
                    event.preventDefault();
                    var selectedRows = ligerGrid_chanpin.getSelectedRows();
                    if(selectedRows.length == 0){
                        top.$.ligerDialog.SQalert({content: "请选中要删除的数据", SQ_type: "warning"});
                        return false; //验证不通过，不执行以下代码
                    }
                    for(var i=0;i<selectedRows.length;i++){
                        ligerGrid_chanpin.deleteRow(selectedRows[i]);
                    }
                    ligerGrid_chanpin.extendDetailAll();
                    var totalContAmt = 0 ;
                    for (var j=0;j<ligerGrid_chanpin.getData().length;j++){
                        totalContAmt += ligerGrid_chanpin.getData()[j].guidePc ;
                    }
                    $("#contAmt").val(totalContAmt) ;

                }
            });
            //  复制一条设备信息
            $("#copyBtn").on("click",function(event){
                event.preventDefault();
                var selectedRows = ligerGrid_chanpin.getSelectedRows();
                if(selectedRows.length == 0){
                    top.$.ligerDialog.SQalert({content: "请选中要复制的数据", SQ_type: "warning"});
                    return false; //验证不通过，不执行以下代码
                }
                for(var i=0;i<selectedRows.length;i++){
                    ligerGrid_chanpin.addRow({
                        brId:selectedRows[i].brId,
                        brCd:selectedRows[i].brCd,
                        modelId:selectedRows[i].modelId,
                        modelNm:selectedRows[i].modelNm,
                        prdNm:selectedRows[i].prdNm,
                        prdId:selectedRows[i].prdId,
                        guidePc:selectedRows[i].guidePc,
                        prdQty:1,
                        prdTypCd:selectedRows[i].prdTypCd,
                        mainTic:selectedRows[i].mainTic,
                        reTic:selectedRows[i].reTic,
                        isCheckOut:selectedRows[i].isCheckOut,
                        checkOutDt:selectedRows[i].checkOutDt,
                        routeId:selectedRows[i].routeId,
                        mediationFeeAmt:selectedRows[i].mediationFeeAmt,
                        preRoutePrpsFeeVOS:selectedRows[i].preRoutePrpsFeeVOS
                    });
                    var totalContAmt = 0 ;
                    for (var j=0;j<ligerGrid_chanpin.getData().length;j++){
                        totalContAmt += ligerGrid_chanpin.getData()[j].guidePc ;
                    }
                    $("#contAmt").val(totalContAmt) ;
                }
                ligerGrid_chanpin.extendDetailAll();
            })
            //设置省和市
            setRgnProvCdUpdataValue('${data.rgnPrCd}');
            setRgnCityCdUpdataValue('${data.rgnCyCd}');
            //初始化时间
            setFormatDateValue();
            //详情页设置不可编辑
            disabledInput();
            //初始化筛选结果
            ligerGrid_route_result_load(editFlag);
            // 展开费用项信息
            if(getIsSecond($("#prjTypCd").val())){
                ligerGrid_esc.extendDetailAll();
            }else{
                ligerGrid_chanpin.extendDetailAll();
            }
            if(routeId){
                showBigCstWork();
            }
        });
        function addEsc(){
            $("#chooseVechDiv").show();
            searchBtn();
            $.ligerDialog.open({ title:'选择车源',target: $("#chooseVechDiv"), width: 900, height:500 });
        }
        var searchBtn = function () {
            var carNo = $("#carNo").val();
            vehSrcListGrid = $("#chooseVech").ligerGrid({
                url: '<%=path%>/project/vehicleSrc/getVehSourceList.do',
                method : 'get',
                parms : {carNo:carNo,prjTypCd:$("#prjTypCd").val()},
                columns: [
                    { display: '车源编号', name: 'carNo', minWidth: 100 ,
                        enabledSort:true},
                    { display: '车型名称', name: 'styleName', minWidth: 100 ,
                        enabledSort:true},
                    { display: '车主姓名', name: 'ownerNm', minWidth: 80 ,
                        enabledSort:true},
                    { display: 'VIN码', name: 'vin', minWidth: 100 , enabledSort:true},
                    { display: '验车状态', name: 'carState', minWidth: 60 , enabledSort:true},
                ],
                usePager:true,
                pageSize:10,
                root:'rows',
                record:'total',
                hideLoadButton : true,
                // width: '100%',
                // height:'100%',
                heightDiff:-2,
                isScroll: false,
                checkbox:true,
                rownumbers:true
            })
        }
        var clearBtn = function(){
            $("#carNo").val("");
        }
        var detailBtn = function () {
            var checkFlag = false ;
            if (!vehSrcListGrid.getSelectedRows() || vehSrcListGrid.getSelectedRows().length != 1){
                top.$.ligerDialog.SQalert({content: "请选择一条车源数据", SQ_type: "warning"});
                return false ;
            }
            // 校验车源信息是否可用
            var carNo = vehSrcListGrid.getSelectedRows()[0].carNo ;
            for(var i=0;i<ligerGrid_esc.getData().length;i++){
                if (ligerGrid_esc.getData()[i].vehNo == carNo){
                    top.$.ligerDialog.SQalert({content: "该车源已在预筛选信息中，请勿重复添加", SQ_type: "warning"});
                    $.ligerDialog.hide();
                    ligerGrid_esc.extendDetailAll() ;
                    return false ;
                }
            }
            var _url = '<%=path%>/project/vehicle/getCheckPrjPrdBscInfo.do';
            $.ajax({
                type: 'get',
                dataType: 'json',
                data: {carNo: carNo},
                url: _url,
                async:false,
                success: function (msg) {
                    if (msg.success == 1) {
                        if (msg.info == 1) {
                            $.ligerDialog.confirm('车源已发起立项，请选择其他车源', function (flag) {
                                if (flag == false) {
                                    $.ligerDialog.hide();//关闭窗口
                                    return false;
                                }
                                $.ligerDialog.hide();//关闭窗口
                            });
                        }else if(msg.info != 1){
                            checkFlag = true
                        }
                    }else{
                        top.$.ligerDialog.SQalert({content: "校验车源是否在项目中发生异常", SQ_type: "warning"});
                    }
                }
            });
            if (!checkFlag){
                // top.$.ligerDialog.SQalert({content: "车源已发起立项，请选择其他车源", SQ_type: "warning"});
                return false ;
            }
            // 将车源信息填入设备表中
            var row = {
                id:'', // 后端生成
                vehId:'', // 车源id
                vehNo:'', // 车源编号
                prdNm:'', // 产品名称
                vehMdl:'', // 车辆型号
                vehAmt:'', // 车辆估值
                lsActAmt:'',// 融资额
                prdQty:1, // 数量
                guidePc:0, // 参考价
                regDt:'', // 登记日期
                releaseDt:'', // 生产日期
                bankNoTypCd:'',// 经销商收款账户类型
                routeId:routeId, // 预筛选id
                preRoutePrpsFeeVOS:initFeeVos // 费用项
            };
            var source = vehSrcListGrid.getSelectedRows()[0] ;
            // 通过id查询车源信息详情
            $.ajax({
                type: 'get',
                dataType: 'json',
                async: false,
                url: '<%=path%>/preinsroute/preRouteBscInfo/carSourceDetail.do',
                async:false,
                data:{
                    id:source.id,
                    prjTypCd:$("#prjTypCd").val()
                },
                success: function (data) {
                    row.vehId = data.carSourceId ; // 车源id
                    row.vehNo = data.carNo ; // 车源编号
                    row.prdNm = data.prdNm ; // 车源网估值
                    row.releaseDt = data.releaseDate ; // 出厂日期
                    row.vehMdl = data.prdMdl; // 车辆型号
                    row.vehAmt = data.vehVal; // 车辆估值
                    row.lsActAmt = data.vehVal; // 融资额
                    row.contAmt = data.vehVal ; // 合同额
                    row.guidePc = data.vehVal ; // 参考价初始化为车辆估值
                    ligerGrid_esc.addRow(row);
                    var contAmt =0;
                    for(var i=0;i<ligerGrid_esc.rows.length;i++){
                        contAmt += ligerGrid_esc.getData()[i].contAmt ;
                    }
                    $("#contAmt").val(contAmt);
                    $.ligerDialog.hide();
                },
                error:function () {
                    top.$.ligerDialog.SQalert({content: "获取车源详细信息失败", SQ_type: "warning"});
                    return false ;
                }
            })
            ligerGrid_esc.extendDetailAll();
        }
        function getIsSecond(prjTypCd) {
            if (prjTypCd == 'CDDYWUL' || prjTypCd == 'ESCJYD' || prjTypCd == 'OWNJYD'){
                return true ;
            }else{
                return false ;
            }
        }
        function f_onSelected(e) {
            if (!e.data || !e.data.length) return;
            var selected = e.data[0];
            var newRow = ligerGrid_chanpin.lastEditRow;
            newRow.brId = selected.key;
            newRow.brCd = selected.value;
            ligerGrid_chanpin.updateRow(ligerGrid_chanpin.lastEditRow, newRow);
            var out = JSON.stringify(selected);
            $("#message").html('最后选择:'+out);
        }
        function ligerGrid_chanpinload(editFlag) {
            ligerGrid_chanpin = $("#grid_chanpin").ligerGrid({
                data:getRows(${preRoutePrdInfoVOS}),
                dataAction:'local',
                columns: [
                    {
                        display: '产品品牌', name: 'brId', minWidth: 100,
                        valueField: 'brId',
                        textField: 'brCd',
                        editor: {
                            type: 'popup', valueField: 'key', textField: 'value', grid:
                                {
                                    data: comboBoxeData, columns: [
                                        { name: 'value', width: 400, display: '产品品牌' }
                                    ]
                                },
                            condition: {
                                prefixID: 'condtion_',
                                fields: [
                                    { name: 'value', type: 'text', label: '产品品牌', width: 200 }
                                ]
                            }, onSelected: f_onSelected,
                            searchClick: function (e)
                            {
                                e.grid.loadData($.ligerFilter.getFilterFunction(e.rules));
                            }
                        },
                        render:function (item) {
                            return item.brCd ;
                        }
                    },
                    {
                        display: '车系/产品名称', name: 'modelId', minWidth: 150,
                        valueField: 'modelId',
                        textField: 'modelNm',
                        editor: {
                            type: 'select',
                            data: '',
                            valueField: 'key',
                            textField: 'value',
                            readonly: true
                        },
                        render: function (item)
                        {
                            return item.modelNm;
                        }
                    },
                    {
                        display: '用途', name: 'prdId', minWidth: 100,
                        valueField: 'prdId',
                        textField: 'prdNm',
                        editor: {
                            type: 'select',
                            data: "",
                            valueField: 'key',
                            textField: 'value',
                            // readonly: true
                        },
                        render: function (item)
                        {
                            return item.prdNm;
                        }
                    },
                    {
                        display: '预估车价（元）', name: 'guidePc', width: 100, align: 'right',
                        editor: {
                            type: 'number',
                            precision: 2,
                            toFix: true,
                            onToFix: function () {
                                $.ligerDialog.SQalert({
                                    SQ_type: "warning",
                                    content: "小数点后面最多2位！"
                                });
                            },
                            render: function (item) {
                                var h = '&yen; ' + SQ.utils.currencyFormatter(item.guidePc, 2)
                                return h;
                            },
                        },
                        render: function (item) {
                            var h = '&yen; ' + SQ.utils.currencyFormatter(item.guidePc, 2)
                            return h;
                        }
                    },
                    {
                        display: '设备数量<span class="sqiconfont sqicon-tishi c_sqYellow gridTip" title="因相同车型多台车情况下可能匹配出不同首付要求，故请逐车维护信息"></span>', name: 'prdQty', width: 80,editable:false,
                        valueField: 'prdQty',
                        textField: 'prdQty'
                    },
                    {
                        display: '主票金额（元）', name: 'mainTic', minWidth: 80,align: 'right',
                        editor: {
                            type: 'text',
                            precision: 2,
                            toFix: true,
                            onToFix: function () {
                                $.ligerDialog.SQalert({
                                    SQ_type: "warning",
                                    content: "小数点后面最多2位！"
                                });
                            },
                        },
                        render: function (item) {
                            var h = '&yen; ' + SQ.utils.currencyFormatter(item.mainTic, 2) ;
                            return h;
                        }
                    },
                    {
                        display: '补票金额（元）', name: 'reTic', minWidth: 80,editable:false,
                        render: function (item) {
                            var h = '&yen; ' + SQ.utils.currencyFormatter(item.reTic, 2)
                            return h;
                        },
                    },
                    {
                        display: '是否提前开票', name: 'isCheckOut', minWidth: 100,
                        valueField: 'key',
                        textField: '',
                        editable: true,
                        editor: {
                            type: 'select',
                            data: yesOrNoCdList,
                            valueField: 'key',
                            textField: 'value',
                        },
                        render:function (item) {
                            if(item.isCheckOut == 1){
                                return "是" ;
                            }else{
                                return "否"
                            }
                        }
                    },
                    {
                        display: '提前开票时间', name: 'checkOutDt', minWidth: 100,
                        editor: {
                            type: 'date'
                        },
                        editable: false,
                        render: function (rowdata, index, value) {
                            var result = '';
                            if (StringUtils.isEmpty(value)) return result;
                            var date = new Date(value);
                            result = date.Format('yyyy-MM-dd');
                            return result;
                        }
                    },
                    {
                        display:'调节费', name:'mediationFeeAmt',minWidth:100,
                        editable: false
                    },
                    {
                        display:'合规机构',name:'insNm',minWidth:200,
                        editable:false,
                        render:function(rowdata, index, value){
                            if(rowdata.preRouteInsResVO){
                                return rowdata.preRouteInsResVO.insNm ;
                            }else{
                                return "";
                            }
                        }
                    }
                ],
                onBeforeEdit: function (e) {
                    var colNanme = e.column.columnname;
                    if (colNanme == "brId") {
                        checkVal = e.record.brId;
                    } else if (colNanme == "modelId") {
                        checkVal = e.record.modelId;
                    } else if (colNanme == "prdId") {
                        checkVal = e.record.prdId;
                    } else if(colNanme == "prdQty"){
                        checkVal = e.record.prdQty ;
                    } else if(colNanme == "guidePc"){
                        checkVal = e.record.guidePc ;
                    } else if(e.column.name =='checkOutDt'){
                        checkVal = e.record.checkOutDt ;
                    }
                    e.column.editor.readonly = false;
                    if (editFlag == "false"){
                        e.column.editor.readonly = true;
                        return ;
                    }
                    if (colNanme == "brId" && e.record.prdTypCd != "2") {
                        e.column.editor.data = comboBoxeList;
                        return ;
                    }
                    if (colNanme == "modelId" && e.record.prdTypCd != "2") {
                        if (e.record.brId){
                            $.ajax({
                                type: 'get',
                                dataType: 'json',
                                async: false,
                                url: '<%=path%>/project/vehicle/carModel.do?brandId=' + e.record.brId,
                                success: function (data) {
                                    e.column.editor.data = data;
                                }
                            });
                        }else{
                            e.column.editor.data = [];
                        }
                        return;
                    }
                    if ((colNanme == "brId" || colNanme == "modelId") && e.record.prdTypCd == "2") {
                        e.column.editor.readonly = true;
                        return ;
                    }
                    if (colNanme == "prdId") {
                        if(e.record.prdTypCd == "2"){
                            $.ajax({
                                type: 'get',
                                dataType: 'json',
                                async: false,
                                url: '<%=path%>/vehicle/trailer/trailerUsageList.do',
                                success: function (data) {
                                    e.column.editor.data = data;
                                }
                            });
                        }else{
                            if (e.record.modelId){
                                $.ajax({
                                    type: 'get',
                                    dataType: 'json',
                                    async: false,
                                    url: '<%=path%>/project/vehicle/carUsage.do?modelId=' + e.record.modelId,
                                    success: function (data) {
                                        e.column.editor.data = data;
                                    }
                                });
                            }else{
                                e.column.editor.data = [];
                            }
                        }
                        return ;
                    }
                    if (e.column.name =='checkOutDt' && e.record.isCheckOut != 1){
                        e.column.editor.readonly = true;
                    }
                    setTimeout(function () {
                        SetIframe_height();
                    }, 0)
                },
                onAfterEdit: function (e) {
                    var colName = e.column.columnname;
                    var recordnew = e.record;
                    var firstAmt = -1;
                    var purchAmt = -1;
                    if (colName == "brId") {
                        if (checkVal != e.record.brId) {
                            recordnew.modelId = '';
                            recordnew.modelNm = '';
                            recordnew.prdId = '';
                            recordnew.guidePc = 0;
                            firstAmt = 0 ;
                            purchAmt = 0 ;
                            recordnew.prdNm = '';
                            ligerGrid_chanpin.updateRow(e.record, recordnew);
                        }
                    }else if(colName == "modelId"){
                        if (checkVal != e.record.modelId) {
                            recordnew.prdId = '';
                            recordnew.prdNm = '';
                            recordnew.guidePc = 0;
                            firstAmt = 0 ;
                            purchAmt = 0 ;
                            ligerGrid_chanpin.updateRow(e.record, recordnew);
                        }
                    }else if (colName == "prdId" ) {
                        if (e.record.prdId && checkVal != e.record.prdId) {
                            recordnew.prdTypCd = getPrdTyp(e.record.prdId);
                            ligerGrid_chanpin.updateRow(e.record, recordnew);
                        }
                    }else if(colName == "guidePc" ){
                        // 更新费用项信息
                        if ($("#"+recordnew.__id).ligerGrid()){
                            firstAmt = recordnew.guidePc * $("#"+recordnew.__id).ligerGrid().rows[0].feePct/100 ;
                            $("#"+recordnew.__id).ligerGrid().updateRow($("#"+recordnew.__id).ligerGrid().rows[0], {"feeAmt": firstAmt}) ;
                            if ($("#"+recordnew.__id).ligerGrid().rows[1].feeTypCd == '01'){
                                purchAmt = recordnew.guidePc * $("#"+recordnew.__id).ligerGrid().rows[1].feePct / 100 ;
                            }else{
                                purchAmt = (recordnew.guidePc - firstAmt) * $("#"+recordnew.__id).ligerGrid().rows[1].feePct / 100 ;
                            }
                        }
                    }else if(colName == "mainTic"){
                        recordnew.reTic = recordnew.guidePc - recordnew.mainTic ;
                        if (recordnew.reTic < 0){
                            recordnew.reTic = 0 ;
                            recordnew.mainTic = recordnew.guidePc ;
                        }
                        ligerGrid_chanpin.updateRow(e.record, recordnew);
                    }else if(colName == 'isCheckOut'){
                        if (recordnew.isCheckOut == 0){
                            recordnew.checkOutDt = '' ;
                        }
                    }
                    // 改变开票金额
                    if (recordnew.mainTic > recordnew.guidePc){
                        recordnew.mainTic = recordnew.guidePc ;
                    }
                    recordnew.reTic = recordnew.guidePc - recordnew.mainTic ;
                    ligerGrid_chanpin.updateRow(e.record, recordnew);
                    // 改变费用项的值
                    if($("#"+recordnew.__id).ligerGrid()){
                        if (firstAmt != -1 && purchAmt != -1){
                            $("#"+recordnew.__id).ligerGrid().updateRow($("#"+recordnew.__id).ligerGrid().rows[0], {"feeAmt":firstAmt}) ;
                            $("#"+recordnew.__id).ligerGrid().updateRow($("#"+recordnew.__id).ligerGrid().rows[1], {"feeAmt":purchAmt}) ;
                        }
                        recordnew.preRoutePrpsFeeVOS = $("#"+recordnew.__id).ligerGrid().getData() ;
                    }
                    var totalContAmt = 0 ;
                    for (var i=0;i<ligerGrid_chanpin.getData().length;i++){
                        totalContAmt += ligerGrid_chanpin.getData()[i].guidePc ;
                    }
                    $("#contAmt").val(totalContAmt) ;
                },
                detail: { onShowDetail: f_showFee },
                detailHeight:100,
                // pageSize: 10,
                // root: 'rows',
                // record: 'total',
                hideLoadButton: true,
                // width: '100%',
                // height: 300,
                heightDiff: -2,
                enabledEdit: editFlag == 'true',
                isScroll: false,
                checkbox: true,
                frozen: false,
                rownumbers: true,
                allowUnSelectRow: true,
                alternatingRow: false,
                enabledSort: false, // 增加行的时候，出现问题，所以不过滤了
                fixedCellHeight: false,
                usePager: false,
                onAfterShowData: function () {
                    SetIframe_height();
                }
            });
            if($("#contAmt").val()){
                $("#contAmt").val(parseFloat($("#contAmt").val()).toString()) ;
            }
        }
        var ligerGrid_escload = function (editFlag) {
            ligerGrid_esc = $("#grid_ershouche").ligerGrid({
                data:getRows(${preRoutePrdInfoVOS}),
                dataAction:'local',
                columns: [
                    {
                        display: '车源编号', name: 'vehNo', minWidth: 100,
                        valueField: 'vehId',
                        textField: 'vehNo',
                    },
                    {
                        display: '产品名称', name: 'prdNm', minWidth: 150,
                        editable:false
                    },
                    {
                        display: '车辆型号', name: 'vehMdl', minWidth: 150,
                        editable:false
                    },
                    {
                        display: '车辆估值（元）', name: 'vehAmt', width: 100, align: 'right',
                        editable:false,
                        render: function (item) {
                            var h = '&yen; ' + SQ.utils.currencyFormatter(item.vehAmt, 2) ;
                            return h;
                        }
                    },
                    {
                        display:'参考价',name:'guidePc',width:120,align:'right',editable:true,
                        editor: {
                            readonly: false,
                            type: 'number',
                            precision: 2,
                            toFix: true,
                            onToFix: function () {
                                $.ligerDialog.SQalert({
                                    SQ_type: "warning",
                                    content: "小数点后面最多2位！"
                                });
                            },
                        },
                        render: function (item) {
                            var h = '&yen; ' + SQ.utils.currencyFormatter(item.guidePc, 2) ;
                            return h;
                        }
                    },
                    {
                        display: '设备数量<span class="sqiconfont sqicon-tishi c_sqYellow gridTip" title="因相同车型多台车情况下可能匹配出不同首付要求，故请逐车维护信息"></span>', name: 'prdQty', width: 80,
                        editable:false,
                        valueField: 'prdQty',
                        textField: 'prdQty'
                    },
                    {
                        display: '融资额', name: 'lsActAmt', width: 100, align: 'right',
                        editable:false,
                        render: function (item) {
                            var h = '&yen; ' + SQ.utils.currencyFormatter(item.contAmt - item.preRoutePrpsFeeVOS[0].feeAmt, 2) ;
                            return h;
                        }
                    },
                    {
                        display: '合同额', name: 'contAmt', width: 100, align: 'right',
                        editable:false,
                        render: function (item) {
                            var h = '&yen; ' + SQ.utils.currencyFormatter(item.contAmt, 2) ;
                            return h;
                        }
                    },
                    {
                        display: '出厂日期', name: 'releaseDt', minWidth: 100,
                        editable: false,
                        editor: {
                            type: 'date',
                            readonly:true
                        },
                        render: function (rowdata, index, value) {
                            var result = '';
                            if (StringUtils.isEmpty(value)) return result;
                            var date = new Date(value);
                            result = date.Format('yyyy-MM-dd');
                            return result;
                        }
                    },
                    {
                        display: '经销商收款账户', name: 'bankNoTypCd', minWidth: 100,
                        valueField: 'bankNoTypCd',
                        textField: '',
                        editable: true,
                        editor: {
                            type: 'select',
                            data: bankNoTypCdList,
                            valueField: 'key',
                            textField: 'value',
                        },
                        render:function (item) {
                            return getValue(bankNoTypCdList,item.bankNoTypCd);
                        }
                    },
                    {
                        display: '经销商省份', name: 'splRgnPrCd', minWidth: 100,
                        valueField: 'splRgnPrCd',
                        textField: '',
                        editable: true,
                        editor: {
                            type: 'select',
                            data: provinceKVList,
                            valueField: 'key',
                            textField: 'value'
                        },
                        render:function(item){
                            return getValue(provinceKVList,item.splRgnPrCd);
                        }
                    },
                    {
                        display:'调节费', name:'mediationFeeAmt',minWidth:100,
                        editable: false
                    },
                    {
                        display:'合规机构',name:'insNm',minWidth:200,
                        editable:false,
                        render:function(rowdata, index, value){
                            if(rowdata.preRouteInsResVO){
                                return rowdata.preRouteInsResVO.insNm ;
                            }else{
                                return "";
                            }
                        }
                    }
                ],
                onBeforeEdit: function (e) {

                },
                onAfterEdit: function (e) {
                    var colNanme = e.column.columnname;
                    var recordnew = e.record ;
                    if (colNanme == "guidePc"){
                        if(e.record.guidePc > e.record.vehAmt && (!e.record.preRouteInsResVO || e.record.preRouteInsResVO.insCode)){
                            $.ligerDialog.SQalert({
                                SQ_type: "warning",
                                content: "参考价不能大于车辆估值！"
                            });
                            recordnew.guidePc = e.record.vehAmt ;
                            recordnew.contAmt = e.record.guidePc + e.record.mediationFeeAmt;
                            ligerGrid_esc.updateRow(e.record, recordnew);
                        }
                        if (e.record.mediationFeeAmt){
                            recordnew.contAmt = e.record.guidePc + e.record.mediationFeeAmt;
                        }else{
                            recordnew.contAmt = e.record.guidePc ;
                        }
                        ligerGrid_esc.updateRow(e.record, recordnew);
                        var totalContAmt = 0 ;
                        for (var i=0;i<ligerGrid_esc.getData().length;i++){
                            totalContAmt += ligerGrid_esc.getData()[i].contAmt ;
                        }
                        $("#contAmt").val(totalContAmt) ;
                    }
                    var firstAmt = -1 ;
                    var purchAmt = -1 ;
                    if ($("#"+recordnew.__id).ligerGrid()){
                        firstAmt = recordnew.contAmt * $("#"+recordnew.__id).ligerGrid().rows[0].feePct/100 ;
                        $("#"+recordnew.__id).ligerGrid().updateRow($("#"+recordnew.__id).ligerGrid().rows[0], {"feeAmt": firstAmt}) ;
                        if ($("#"+recordnew.__id).ligerGrid().rows[1].feeTypCd == '01'){
                            purchAmt = recordnew.contAmt * $("#"+recordnew.__id).ligerGrid().rows[1].feePct / 100 ;
                        }else{
                            purchAmt = (recordnew.contAmt - firstAmt) * $("#"+recordnew.__id).ligerGrid().rows[1].feePct / 100 ;
                        }
                    }
                    // 改变费用项的值
                    if($("#"+recordnew.__id).ligerGrid()){
                        if (firstAmt != -1 && purchAmt != -1){
                            $("#"+recordnew.__id).ligerGrid().updateRow($("#"+recordnew.__id).ligerGrid().rows[0], {"feeAmt":firstAmt}) ;
                            $("#"+recordnew.__id).ligerGrid().updateRow($("#"+recordnew.__id).ligerGrid().rows[1], {"feeAmt":purchAmt}) ;
                        }
                        recordnew.preRoutePrpsFeeVOS = $("#"+recordnew.__id).ligerGrid().getData() ;
                    }
                },
                detail: { onShowDetail: f_showFee },
                detailHeight:100,
                // pageSize: 10,
                // root: 'rows',
                // record: 'total',
                hideLoadButton: true,
                // width: '100%',
                // height: 300,
                heightDiff: -2,
                enabledEdit: editFlag == 'true',
                isScroll: false,
                checkbox: true,
                frozen: false,
                rownumbers: true,
                allowUnSelectRow: false,
                alternatingRow: false,
                enabledSort: false, // 增加行的时候，出现问题，所以不过滤了
                fixedCellHeight: false,
                usePager: false,
                onAfterShowData: function () {
                    SetIframe_height();
                }
            });
            if($("#contAmt").val()){
                $("#contAmt").val(parseFloat($("#contAmt").val()).toString()) ;
            }
            if (getIsSecond($("#prjTypCd").val()) && ligerGrid_esc){
                if($("#prjTypCd").val() != 'ESCJYD' && $("#prjTypCd").val() != 'OWNJYD'){
                    ligerGrid_esc.toggleCol('splRgnPrCd', false);
                }else{
                    ligerGrid_esc.toggleCol('splRgnPrCd', true);
                }
                if($("#prjTypCd").val() == 'CDDYWUL'){
                    ligerGrid_esc.toggleCol('lsActAmt', true);
                }else{
                    ligerGrid_esc.toggleCol('lsActAmt', false);
                }
            }
        }
        //设置日期值
        function setFormatDateValue() {
            var licDt = '${data.licDt}';
            if (licDt) {
                var licDate = DateUtils.formatDate(new Date(licDt), DateUtils.YYYY_MM_DD);
                $("#licDt").val(licDate);
            }
            var licAgainDt = '${data.licAgainDt}';
            if (licAgainDt) {
                var licAgainDt = DateUtils.formatDate(new Date(licAgainDt), DateUtils.YYYY_MM_DD);
                $("#licAgainDt").val(licAgainDt);
            }
        }
        function disabledInput() {
            if(editFlag == "false") {
                liger.get("cstNm").setDisabled();
                liger.get("prjTypCd").setDisabled();
                liger.get("isFarmer").setDisabled();
                liger.get("isBigCstWork").setDisabled();
                liger.get("isBp").setDisabled();
                liger.get("lsPd").setDisabled();
                liger.get("lsPdUntCd").setDisabled();
                liger.get("annIntRatePct").setDisabled();
                liger.get("isSplMfr").setDisabled();
                liger.get("isPreInt").setDisabled();
                liger.get("rgnProvCd").setDisabled();
                liger.get("rgnCityCd").setDisabled();
                liger.get("isLic").setDisabled();
                liger.get("licDt").setDisabled();
                liger.get("isLicAgain").setDisabled();
                liger.get("licAgainDt").setDisabled();
                $("#chooseCstBtnDiv").hide();
                $("#addBtnDiv").hide();
                $("#filterBtn").hide();
            }
        }
        //显示费用项
        function f_showFee(row, detailPanel,callback){
            var ligerDiv = document.createElement('div');
            if(document.getElementById(row.__id)){
                document.getElementById(row.__id).parentNode.removeChild(document.getElementById(row.__id));
            }
            $(ligerDiv).attr("id",row.__id) ;
            $(detailPanel).append(ligerDiv);
            var ligerGrid_baojia = $(ligerDiv).css('height', 100).ligerGrid({
                data: !row.preRoutePrpsFeeVOS || row.preRoutePrpsFeeVOS.length == 0 ? getRows(${preRoutePrpsFeeVOS}):getRows(row.preRoutePrpsFeeVOS),
                dataAction:'local',
                columns: [
                    {
                        display: '费用类型', name: 'feeTypCd',
                        valueField: 'feeTypCd',
                        textField: 'feeTypCdNm',
                        render:function(item){
                            if (item.feeTypCd == '01'){
                                return '首期' ;
                            }
                            if (item.feeTypCd == '02'){
                                return "客户保证金";
                            }
                        }
                    },
                    {
                        display: '计算基数', name: 'calBaseCd',
                        valueField: 'calBaseCd',
                        textField: 'calBaseCdNm',
                        editor: {
                            type: 'select',
                            data: calBaseCdListJSON,
                            valueField: 'key',
                            textField: 'value'
                        },
                        render: function (item) {
                            if (item.calBaseCd == 2){
                                item.calBaseCdNm = '融资额';
                                return '融资额' ;
                            }
                            if (item.calBaseCd == 1){
                                item.calBaseCdNm = '合同总额';
                                return "合同总额";
                            }
                        }
                    },
                    { display: '比例值（%）', name: 'feePct', minWidth: 60,
                        editor: {type: 'number',
                            precision: 10,
                            max:100,
                            toFix: true,
                            onToFix: function () {
                                $.ligerDialog.SQalert({
                                    SQ_type: "warning",
                                    content: "小数点后面最多2位！"
                                });
                            }
                        },
                        render:function(item){
                            var pct = "" ;
                            if(item.feePct && typeof item.feePct =='number'){
                                pct =  (parseFloat(item.feePct)).toFixed(2)
                            }else {
                                pct = "0.00" ;
                            }
                            return pct ;
                        }
                    },
                    {
                        display: '金额（元）', name: 'feeAmt',minWidth: 60 ,
                        editor: {type: 'number',
                            precision: 2,
                            max:100,
                            toFix: true,
                            onToFix: function () {
                                $.ligerDialog.SQalert({
                                    SQ_type: "warning",
                                    content: "小数点后面最多2位！"
                                });
                            }
                        },
                        render: function (item) {
                            var h = '&yen; ' + SQ.utils.currencyFormatter(item.feeAmt, 2)
                            return h;
                        },
                    },
                    {
                        display: '计入方式', name: 'cntWayCdNm', editable:false,
                        render:function () {
                            return "首期款";
                        }
                    },
                ],
                onBeforeEdit: function (e) {
                    setTimeout(function(){SetIframe_height();},0);
                    if(e.record.isAllowChg == 0){
                        e.column.editor.readonly = true;
                    }else if (e.column.name == "calBaseCd") {
                        if(e.record.feeTypCd == "01"){
                            e.column.editor.readonly = true;
                        }else{
                            e.column.editor.data = [{'key':'1','value':'合同总额'},{'key':'2','value':'融资额'}];
                            e.column.editor.readonly = false;
                        }
                    } else {
                        e.column.editor.readonly = false;
                    }
                    if (editFlag == "false") {
                        e.column.editor.readonly = true;
                    }
                },
                onAfterEdit: function (e) {
                    var colNanme = e.column.columnname;
                    var rows = ligerGrid_baojia.rows;
                    var calBaseCd = rows[1].calBaseCd;
                    if(colNanme == "feePct"){
                        if (e.record.feePct > 100){
                            top.$.ligerDialog.SQalert({content: "比例值不能超过100%！", SQ_type: "warning"});
                            e.record.feePct = 0 ;
                            ligerGrid_baojia.updateCell("feePct",0,rows[0]);
                            return false ;
                        }
                        if (e.record.feePct < 0){
                            top.$.ligerDialog.SQalert({content: "比例值不能小于0%！", SQ_type: "warning"});
                            e.record.feePct = 0 ;
                            ligerGrid_baojia.updateCell("feePct",0,rows[0]);
                            return false ;
                        }
                        var contAmt = getIsSecond($("#prjTypCd").val())?row.contAmt:row.guidePc ;
                        var fee01 = (rows[0].feePct * contAmt/100);
                        var fee02 = 0;
                        if (ligerGrid_baojia.rows[1].calBaseCd == 1){
                            fee02 = (contAmt * rows[1].feePct/100);
                        }else{
                            fee02 = ((contAmt-fee01) * rows[1].feePct/100);
                        }
                        ligerGrid_baojia.updateCell("feeAmt",fee01,rows[0]);
                        ligerGrid_baojia.updateCell("feeAmt",fee02,rows[1]);
                        if ($("#prjTypCd").val() == 'CDDYWUL') {
                            var newRow = row ;
                            newRow.lsActAmt = contAmt - fee01 ;
                            ligerGrid_esc.updateRow(row,newRow);
                        }
                    }
                    if(colNanme == "feeAmt"){
                        var contAmt = getIsSecond($("#prjTypCd").val())?row.contAmt:row.guidePc ;
                        if(contAmt != 0){
                            if(e.record.feeTypCd == "01"){
                                var feePct = ((rows[0].feeAmt / contAmt)*100);
                                if(calBaseCd == 2){
                                    fee02 = (rows[1].feePct*(contAmt-rows[0].feeAmt)/100);
                                }else{
                                    fee02 = (rows[1].feePct*contAmt/100);
                                }
                                ligerGrid_baojia.updateCell("feePct",feePct,rows[0]);
                                ligerGrid_baojia.updateCell("feeAmt",fee02,rows[1]);
                            }else{
                                var feePct = 0;
                                if(calBaseCd == 2){
                                    feePct = ((rows[1].feeAmt / (contAmt-rows[0].feeAmt))*100);
                                }else{
                                    feePct = ((rows[1].feeAmt / contAmt)*100);
                                }
                                ligerGrid_baojia.updateCell("feePct",feePct,rows[1]);
                            }
                        }else{
                            ligerGrid_baojia.updateCell("feeAmt",0,rows[0]);
                            ligerGrid_baojia.updateCell("feeAmt",0,rows[1]);
                        }
                        if ($("#prjTypCd").val() == 'CDDYWUL') {
                            var newRow = row ;
                            newRow.lsActAmt = contAmt - fee01 ;
                            ligerGrid_esc.updateRow(row,newRow);
                        }
                    }
                    if(colNanme == "calBaseCd" && (e.record.feeTypCd == "02")){
                        var contAmt = getIsSecond($("#prjTypCd").val())?row.contAmt:row.guidePc ;
                        var fee02 = 0;
                        if(calBaseCd == 2){
                            fee02 = (rows[1].feePct * (contAmt-rows[0].feeAmt)/100);
                        }else{
                            fee02 = (rows[1].feePct * contAmt/100);
                        }
                        ligerGrid_baojia.updateCell("feeAmt",fee02,rows[1]);
                    }
                    // 遍历产品列表，费用项为空的，将费用项比例设置为当前行比例
                    var gridvehicle ;
                    if(getIsSecond($("#prjTypCd").val())){
                        gridvehicle = ligerGrid_esc ;
                    }else{
                        gridvehicle = ligerGrid_chanpin;
                    }
                    for(var i=0;i<gridvehicle.getData().length;i++){
                        var feeGrid = $("#"+gridvehicle.rows[i].__id).ligerGrid() ;
                        var contAmt = 0 ;
                        if (getIsSecond($("#prjTypCd").val())){
                            contAmt = gridvehicle.rows[i].contAmt ;
                        }else{
                            contAmt = gridvehicle.rows[i].guidePc ;
                        }
                        if(feeGrid){
                            if(e.record.feeTypCd == 1){ // 修改的是首期. 更新每个费用项列表的第一行
                                var firstPct = e.record.feePct ;
                                var firstAmt = (contAmt * firstPct/100) ;
                                // 改变费用项的值
                                if(feeGrid.rows[0].feePct == null || feeGrid.rows[0].feePct === ""){
                                    $("#"+gridvehicle.rows[i].__id).ligerGrid().updateRow($("#"+gridvehicle.rows[i].__id).ligerGrid().rows[0], {"feePct":firstPct,"feeAmt":firstAmt}) ;
                                }
                                var purchPct = $("#"+gridvehicle.rows[i].__id).ligerGrid().rows[1].feePct ;
                                purchPct = purchPct==""?0:purchPct ;
                                var purchAmt = 0 ;
                                if ($("#"+gridvehicle.rows[i].__id).ligerGrid().rows[1].calBaseCd == 1){
                                    purchAmt =  (contAmt * purchPct/100);
                                }else{
                                    purchAmt =  ((contAmt -  $("#"+gridvehicle.rows[i].__id).ligerGrid().rows[0].feeAmt) * purchPct/100) ;
                                }
                                $("#"+gridvehicle.rows[i].__id).ligerGrid().updateRow($("#"+gridvehicle.rows[i].__id).ligerGrid().rows[1], {"feeAmt":purchAmt}) ;
                            }
                            if (e.record.feeTypCd == 2){ // 修改的是客户保证金
                                var purchPct = e.record.feePct ;
                                var purchAmt = 0 ;
                                if (e.record.calBaseCd == 1){
                                    purchAmt =  (contAmt * purchPct/100) ;
                                }else{
                                    purchAmt =  ((contAmt -  $("#"+gridvehicle.rows[i].__id).ligerGrid().rows[0].feeAmt) * purchPct/100) ;
                                }
                                // 改变费用项的值
                                if(feeGrid.rows[1].feePct == null || feeGrid.rows[1].feePct === ''){
                                    $("#"+gridvehicle.rows[i].__id).ligerGrid().updateRow($("#"+gridvehicle.rows[i].__id).ligerGrid().rows[1], {"feePct":purchPct,"feeAmt":purchAmt}) ;
                                }
                            }
                            gridvehicle.rows[i].preRoutePrpsFeeVOS = $("#"+gridvehicle.rows[i].__id).ligerGrid().getData() ;
                        }
                    }
                    row.preRoutePrpsFeeVOS = ligerGrid_baojia.getData() ;

                },
                onBeforeSubmitEdit: function (e) {
                },
                // pageSize: 10,
                // root: 'rows',
                // record: 'total',
                hideLoadButton: true,
                width: '100%',
                height: 100,
                // heightDiff: -2,
                enabledEdit: editFlag == 'true',
                isScroll: false,
                // checkbox: true,
                frozen: false,
                rownumbers: true,
                // allowUnSelectRow: true,
                alternatingRow: false,
                enabledSort: false, // 增加行的时候，出现问题，所以不过滤了
                fixedCellHeight: false,
                usePager: false,
                // onAfterShowData: function() {
                //     SetIframe_height();
                // },
            });
            row.preRoutePrpsFeeVOS = ligerGrid_baojia.getData() ;
        }
        function ligerGrid_route_result_load() {
            if (editFlag == "false") {
                $.ajax({
                    type: 'get',
                    url: '<%=path%>/preinsroute/preRouteBscInfo/searchPrerouteResult.do',
                    dataType:'json',
                    data: {
                        routeId: routeId
                    },
                    async: false,
                    success: function (result) {
                        if (result && result.insSts != 0 && result.rows.length > 0) {
                            $("#grid_route_result").show();
                            $("#grid_route_result").ligerGrid({
                                data: result,
                                dataAction: 'local',
                                columns: [
                                    {
                                        display: '合规机构名称', name: 'insNm', minWidth: 100,
                                        editable: false
                                    },
                                    {
                                        display: '设备信息', name: 'preRoutePrdInfoVOS', minWidth: 100,
                                        editable: false,
                                        render: function (item) {
                                            var html = '';
                                            if(item.preRoutePrdInfoVOS){
                                                for(var i=0;i<item.preRoutePrdInfoVOS.length;i++){
                                                    if(item.preRoutePrdInfoVOS[i].flag){
                                                        html += item.preRoutePrdInfoVOS[i].prdNm + '-' + item.preRoutePrdInfoVOS[i].brCd + '-' + item.preRoutePrdInfoVOS[i].modelNm + '<br/>';
                                                    }else{
                                                        html += item.preRoutePrdInfoVOS[i].prdNm + '<br/>';
                                                    }
                                                }
                                            }
                                            return html;
                                        }
                                    },
                                    {
                                        display: '机构提示信息', name: 'gctDes', minWidth: 100,
                                        editable: false
                                    },
                                    {
                                        display: '追加调节费', name: 'feeDes', minWidth: 100,
                                        editable: false,
                                        render:function (item) {
                                            if (item.feeDes){
                                                return item.feeDes ;
                                            }else{
                                                return "" ;
                                            }
                                        }
                                    }
                                ],
                                usePager: false,
                                root: 'rows',
                                record: 'total',
                                hideLoadButton: true,
                                width: '100%',
                                height: '100%',
                                heightDiff: -2,
                                enabledEdit: false,
                                isScroll: false,
                                checkbox: false,
                                frozen: false,
                                rownumbers: true,
                                allowUnSelectRow: true,
                                alternatingRow: false,
                                // enabledSort: false, // 增加行的时候，出现问题，所以不过滤了
                                fixedCellHeight: false,
                                usePager: false,
                                onAfterShowData: function () {
                                    SetIframe_height();
                                }
                            });
                        } else {
                            $("#route_result_tip").show();
                        }
                    },
                    error: function () {

                    }
                })
            }
        }

        // 获取车的类型 （1-头车，2-挂车，3-一体车）
        var getPrdTyp = function (prdId) {
            for(var i=0;i<prdTypKVList.length;i++){
                if (prdTypKVList[i].key == prdId){
                    return prdTypKVList[i].value ;
                }
            }
        }

        function setLicDtShow() {
            var isLic = $("#isLic").val();
            if (isLic == '1') {
                $("#licDtdiv").show();
            } else {
                $("#licDtdiv").hide();
                $("#licDt").val("");
            }
        }

        function setLicAgainDtShow() {
            var isLicAgain = $("#isLicAgain").val();
            if (isLicAgain == '1') {
                $("#licAgainDtdiv").show();
            } else {
                $("#licAgainDtdiv").hide();
                $("#licAgainDt").val("");
            }
        }
        // 提交
        var showTips = function(){
            var tips = "系统筛选后如需添加调节费，系统将默认添加调节费并自动修改设备款、合同额、首付金额、首付比例、补票金额，请知悉";
            if(getIsSecond($("#prjTypCd").val())){
                tips = "系统筛选后如需添加调节费，系统将默认添加调节费并自动修改合同额、首付金额、首付比例，请知悉";
            }
            top.$.ligerDialog.confirm(tips, function (flag) {
                if (!flag){
                    return false ;
                }else{
                    submitPreRoute() ;
                }
            });
        }
        var submitPreRoute = function(){
            $("#filterBtn").attr('onclick','');
            if (routeId){
                if (!checkCstRisk(1)){
                    $("#filterBtn").attr('onclick','submitPreRoute()');
                    return false ;
                }
            }
            var params = {
                id:routeId,
                cstId:$("#cstId").val(),
                cstNm:$("#cstNm").val(),
                prjTypCd:$("#prjTypCd").val(),
                isFarmer:$("#isFarmer").val(),
                isBigCstWork:$("#isBigCstWork").val(),
                rgnPrCd:$("#rgnProvCd_val").val(),
                rgnCyCd:$("#rgnCityCd_val").val(),
                isLic:$("#isLic").val(),
                licDt:$("#licDt").val(),
                isLicAgain:$("#isLicAgain").val(),
                licAgainDt:$("#licAgainDt").val(),
                contAmt:$("#contAmt").val(),
                lsPd:$("#lsPd").val(),
                lsPdUntCd:$("#lsPdUntCd").val(),
                isSplMfr:$("#isSplMfr").val(),
                isPreInt:$("#isPreInt").val(),
                annIntRatePct:$("#annIntRatePct").val(),
                isBp:$("#isBp").val(),
                dsCd:"CHL0001",
                isVisit:$("#isVisit").val(),
                payWayCd:$("#payWayCd").val(),
                // isDel:$("#isBp").val(), 是否删除
                // cstMgrId:$("#isBp").val(), 客户经理id
                // cstMgrNm:$("#isBp").val(), 客户经理name
                // cstMgrOrgCd:$("#isBp").val(), 客户经理所属机构
                // buOrgCd:$("#isBp").val(), 机构代码
                // isValid:$("#isBp").val(), 是否可用
                // insSts:$("#isBp").val(), 筛选状态
                // ------------  以下是  设备信息 ----------------------
                preRoutePrdInfoVOS:getIsSecond($("#prjTypCd").val())?ligerGrid_esc.rows:ligerGrid_chanpin.rows,
            };
            // ---------------------参数校验 ---------------------------
            if (!params.preRoutePrdInfoVOS || params.preRoutePrdInfoVOS.length == 0){
                top.$.ligerDialog.SQalert({content: "请先添加设备！", SQ_type: "warning"});
                $("#filterBtn").attr('onclick','submitPreRoute()');
                return false ;
            }
            if (!params.cstId){
                top.$.ligerDialog.SQalert({content: "请选择客户！", SQ_type: "warning"});
                $("#filterBtn").attr('onclick','submitPreRoute()');
                return false ;
            }
            if (!params.prjTypCd){
                top.$.ligerDialog.SQalert({content: "请选择项目类型！", SQ_type: "warning"});
                $("#filterBtn").attr('onclick','submitPreRoute()');
                return false ;
            }
            if (!params.annIntRatePct){
                top.$.ligerDialog.SQalert({content: "请填写租赁年利率！", SQ_type: "warning"});
                $("#filterBtn").attr('onclick','submitPreRoute()');
                return false ;
            }
            if (params.annIntRatePct < 0){
                top.$.ligerDialog.SQalert({content: "租赁年利率不能为负数！", SQ_type: "warning"});
                $("#filterBtn").attr('onclick','submitPreRoute()');
                return false ;
            }
            if(params.annIntRatePct.indexOf('.') > 0 && params.annIntRatePct.length - params.annIntRatePct.indexOf('.') > 3){
                top.$.ligerDialog.SQalert({content: "租赁年利率最大精度为0.01%！", SQ_type: "warning"});
                $("#filterBtn").attr('onclick','submitPreRoute()');
                return false ;
            }
            if (!params.lsPd){
                top.$.ligerDialog.SQalert({content: "请填写租赁期数！", SQ_type: "warning"});
                $("#filterBtn").attr('onclick','submitPreRoute()');
                return false ;
            }
            if(params.lsPd <= 0 || params.lsPd.indexOf('.') != -1){
                top.$.ligerDialog.SQalert({content: "租赁期数只能为正整数！", SQ_type: "warning"});
                $("#filterBtn").attr('onclick','submitPreRoute()');
                return false ;
            }
            if (StringUtils.isEmpty(params.rgnPrCd)){
                top.$.ligerDialog.SQalert({content: "请选择上牌省份！", SQ_type: "warning"});
                $("#filterBtn").attr('onclick','submitPreRoute()');
                return false ;
            }
            if (StringUtils.isEmpty(params.rgnCyCd)){
                top.$.ligerDialog.SQalert({content: "请选择上牌城市！", SQ_type: "warning"});
                $("#filterBtn").attr('onclick','submitPreRoute()');
                return false ;
            }
            if(getIsSecond($("#prjTypCd").val())){
                if (StringUtils.isEmpty(params.isVisit)){
                    top.$.ligerDialog.SQalert({content: "请选择是否有家访费！", SQ_type: "warning"});
                    $("#filterBtn").attr('onclick','submitPreRoute()');
                    return false ;
                }
                if (StringUtils.isEmpty(params.payWayCd)){
                    top.$.ligerDialog.SQalert({content: "请选择还款方式！", SQ_type: "warning"});
                    $("#filterBtn").attr('onclick','submitPreRoute()');
                    return false ;
                }
            }else{
                if (params.isLic == 1 && StringUtils.isEmpty(params.licDt)){
                    top.$.ligerDialog.SQalert({content: "请填写上牌时间！", SQ_type: "warning"});
                    $("#filterBtn").attr('onclick','submitPreRoute()');
                    return false ;
                }
                if (params.isLicAgain == 1 && StringUtils.isEmpty(params.licAgainDt)){
                    top.$.ligerDialog.SQalert({content: "请填写再次上牌时间！", SQ_type: "warning"});
                    $("#filterBtn").attr('onclick','submitPreRoute()');
                    return false ;
                }
            }
            for (var i=0;i<params.preRoutePrdInfoVOS.length;i++){
                if (StringUtils.isEmpty(params.preRoutePrdInfoVOS[i].prdQty) || params.preRoutePrdInfoVOS[i].prdQty <= 0){
                    top.$.ligerDialog.SQalert({content: "请填写设备数量", SQ_type: "warning"});
                    $("#filterBtn").attr('onclick','submitPreRoute()');
                    return false ;
                }
                if(getIsSecond($("#prjTypCd").val())){
                    if (StringUtils.isEmpty(params.preRoutePrdInfoVOS[i].releaseDt)) {
                        top.$.ligerDialog.SQalert({content: "请填写出厂日期", SQ_type: "warning"});
                        $("#filterBtn").attr('onclick','submitPreRoute()');
                        return false ;
                    }
                    if (StringUtils.isEmpty(params.preRoutePrdInfoVOS[i].guidePc) || params.preRoutePrdInfoVOS[i].guidePc <= 0){
                        top.$.ligerDialog.SQalert({content: "请填写参考价", SQ_type: "warning"});
                        $("#filterBtn").attr('onclick','submitPreRoute()');
                        return false ;
                    }
                    if (StringUtils.isEmpty(params.preRoutePrdInfoVOS[i].bankNoTypCd)){
                        top.$.ligerDialog.SQalert({content: "请选择经销商收款账户", SQ_type: "warning"});
                        $("#filterBtn").attr('onclick','submitPreRoute()');
                        return false ;
                    }
                    if (StringUtils.isEmpty(params.preRoutePrdInfoVOS[i].splRgnPrCd) && ($("#prjTypCd").val() == 'ESCJYD' || $("#prjTypCd").val() == 'OWNJYD')){
                        top.$.ligerDialog.SQalert({content: "请选择经销商省份", SQ_type: "warning"});
                        $("#filterBtn").attr('onclick','submitPreRoute()');
                        return false ;
                    }
                }else{
                    if (StringUtils.isEmpty(params.preRoutePrdInfoVOS[i].guidePc) || params.preRoutePrdInfoVOS[i].guidePc <= 0){
                        top.$.ligerDialog.SQalert({content: "请填写预估车价", SQ_type: "warning"});
                        $("#filterBtn").attr('onclick','submitPreRoute()');
                        return false ;
                    }
                    if (StringUtils.isEmpty(params.preRoutePrdInfoVOS[i].prdId)){
                        top.$.ligerDialog.SQalert({content: "请选择用途", SQ_type: "warning"});
                        $("#filterBtn").attr('onclick','submitPreRoute()');
                        return false ;
                    }
                    if (params.preRoutePrdInfoVOS[i].isCheckOut == 1 && StringUtils.isEmpty(params.preRoutePrdInfoVOS[i].checkOutDt)){
                        top.$.ligerDialog.SQalert({content: "请填写开票日期", SQ_type: "warning"});
                        $("#filterBtn").attr('onclick','submitPreRoute()');
                        return false ;
                    }
                    if(StringUtils.isEmpty(params.preRoutePrdInfoVOS[i].mainTic) || params.preRoutePrdInfoVOS[i].mainTic <= 0){
                        top.$.ligerDialog.SQalert({content: "主票金额不能为0", SQ_type: "warning"});
                        $("#filterBtn").attr('onclick','submitPreRoute()');
                        return false ;
                    }
                    if(StringUtils.isEmpty(params.preRoutePrdInfoVOS[i].reTic) || params.preRoutePrdInfoVOS[i].reTic < 0){
                        top.$.ligerDialog.SQalert({content: "补票金额不能为负数", SQ_type: "warning"});
                        $("#filterBtn").attr('onclick','submitPreRoute()');
                        return false ;
                    }
                }
                if(!params.preRoutePrdInfoVOS[i].preRoutePrpsFeeVOS || params.preRoutePrdInfoVOS[i].preRoutePrpsFeeVOS.length == 0){
                    top.$.ligerDialog.SQalert({content: "请完善第" + (i+1) + "台设备的费用项信息", SQ_type: "warning"});
                    $("#filterBtn").attr('onclick','submitPreRoute()');
                    return false ;
                }else{
                    for(var j = 0;j<params.preRoutePrdInfoVOS[i].preRoutePrpsFeeVOS.length;j++){
                        if(StringUtils.isEmpty(params.preRoutePrdInfoVOS[i].preRoutePrpsFeeVOS[j].feePct) || StringUtils.isEmpty(params.preRoutePrdInfoVOS[i].preRoutePrpsFeeVOS[j].feeAmt)){
                            top.$.ligerDialog.SQalert({content: "第" + (i+1) + "台设备的费用比例不能为空", SQ_type: "warning"});
                            $("#filterBtn").attr('onclick','submitPreRoute()');
                            return false ;
                        }
                        if(StringUtils.isEmpty(params.preRoutePrdInfoVOS[i].preRoutePrpsFeeVOS[j].calBaseCd) || StringUtils.isEmpty(params.preRoutePrdInfoVOS[i].preRoutePrpsFeeVOS[j].calBaseCd)){
                            top.$.ligerDialog.SQalert({content: "第" + (i+1) + "台设备的费用计算基数不能为空", SQ_type: "warning"});
                            $("#filterBtn").attr('onclick','submitPreRoute()');
                            return false ;
                        }
                        if(params.preRoutePrdInfoVOS[i].preRoutePrpsFeeVOS[j].feePct < 0){
                            top.$.ligerDialog.SQalert({content: "第" + (i+1) + "台设备的费用比例不能为负数", SQ_type: "warning"});
                            $("#filterBtn").attr('onclick','submitPreRoute()');
                            return false ;
                        }
                        if(params.preRoutePrdInfoVOS[i].preRoutePrpsFeeVOS[j].feeAmt < 0){
                            top.$.ligerDialog.SQalert({content: "第" + (i+1) + "台设备的费用金额不能为负数", SQ_type: "warning"});
                            $("#filterBtn").attr('onclick','submitPreRoute()');
                            return false ;
                        }
                        if(params.preRoutePrdInfoVOS[i].mediationFeeAmt && params.preRoutePrdInfoVOS[i].preRoutePrpsFeeVOS[j].feeTypCd == '01' && params.preRoutePrdInfoVOS[i].preRoutePrpsFeeVOS[j].feeAmt < params.preRoutePrdInfoVOS[i].mediationFeeAmt){
                            top.$.ligerDialog.SQalert({content: "第" + (i+1) + "台设备,首付金额不可低于调节费，请核实", SQ_type: "warning"});
                            $("#filterBtn").attr('onclick','submitPreRoute()');
                            return false ;
                        }
                    }
                }
            }
            $.ajax({
                type: 'post',
                dataType: 'json',
                contentType: 'application/json',
                data: JSON.stringify(params),
                url: '<%=path%>/preinsroute/preRouteBscInfo/addOrModify.do',
                success: function (result) {
                    if (result && result.success == 1) {
                        $("#filterBtn").hide();
                        $("#viewResult").show();
                        routeId = result.data;
                        // top.$.ligerDialog.SQalert({content: "数据保存成功！", SQ_type: "success"});
                        //筛选结果的方法
                        showRouteResult();
                    } else {
                        top.$.ligerDialog.SQalert({content: "数据保存失败！" + result.info, SQ_type: "success"});
                        $("#filterBtn").attr('onclick','submitPreRoute()');
                    }
                },
                error:function(){
                    top.$.ligerDialog.SQalert({content: "数据保存失败！" + result.info, SQ_type: "error"});
                    $("#filterBtn").attr('onclick','submitPreRoute()');
                }
            });
        }
        var showRouteResult = function() {
            $.ajax({
                type:'get',
                url:'<%=path%>/preinsroute/preRouteBscInfo/searchPrerouteResult.do?routeId=' + routeId,
                data:"",
                success:function(result){
                    result = JSON.parse(result);
                    if (result && result.insSts != 0 && result.rows.length > 0){
                        $("#preRouteResult").show() ;
                        liger_route_result = $("#preRouteResult_div").ligerGrid({
                            data:result,
                            dataAction:'local',
                            columns: [
                                {
                                    display: '合规机构', name: 'insNm', minWidth: 50,
                                    editable: false,
                                },
                                {
                                    display: '设备信息', name: 'preRoutePrdInfoVOS', minWidth: 50,
                                    editable: false,
                                    render: function (item) {
                                        var html = '';
                                        for(var i=0;i<item.preRoutePrdInfoVOS.length;i++){
                                            if(getPrdTyp(item.preRoutePrdInfoVOS[i].prdId) != 2) {
                                                html += '<span>' + item.preRoutePrdInfoVOS[i].prdNm + '—' + item.preRoutePrdInfoVOS[i].brCd + '—' + item.preRoutePrdInfoVOS[i].modelNm + '</span><br/>';
                                            }else{
                                                html += '<span>' + item.preRoutePrdInfoVOS[i].prdNm + '—' + '</span><br/>';
                                            }
                                        }
                                        return html;
                                    }
                                },
                                {
                                    display: '机构提示信息', name: 'gctDes', minWidth: 50,
                                    editable: false,
                                    render:function(item){
                                        return '<div style="white-space: normal;text-align: left;">' + item.gctDes + '</div>'
                                    }
                                },
                                {
                                    display: '追加调节费', name: 'feeDes', minWidth: 50,
                                    editable: false,
                                    render:function(item){
                                        if (item.feeDes){
                                            return '<div style="white-space: normal;text-align: left;">' + item.feeDes + '</div>'
                                        }else{
                                            return "" ;
                                        }
                                    }
                                }
                            ],
                            usePager: false,
                            root: 'rows',
                            record: 'total',
                            hideLoadButton: true,
                            width: '100%',
                            height: '100%',
                            heightDiff: -2,
                            enabledEdit: false,
                            isScroll: false,
                            checkbox: false,
                            frozen: false,
                            rownumbers: true,
                            allowUnSelectRow: true,
                            alternatingRow: false,
                            // enabledSort: false, // 增加行的时候，出现问题，所以不过滤了
                            fixedCellHeight: false,
                            usePager: false,
                            onAfterShowData: function () {
                                SetIframe_height();
                            }
                        });
                        $.ligerDialog.close();
                        $.ligerDialog.open({
                            width: 800,
                            minHeight: 800,
                            // top: 500,
                            title: '筛选结果',
                            target: $("#preRouteResult"),
                        });
                    } else if (countdownNum > 3) {
                        $.ligerDialog.close();
                        $.ligerDialog.open({
                            width: 800,
                            minHeight: 500,
                            // top: 500,
                            title: '筛选结果',
                            target: $("#preRouteLoadEnd"),
                        });
                    } else {
                        $.ligerDialog.close();
                        $.ligerDialog.open({
                            width: 800,
                            minHeight: 500,
                            // top: 500,
                            title: '筛选结果',
                            target: $("#preRouteLoading"),
                        });
                        countDownFun(5);
                    }
                },
                error:function (){

                }
            })
        }
        function getRows(dataList){
            var data = { Rows: [],total:0};
            if (dataList === undefined){
                return data;
            }
            for (var i = 0; i < dataList.length; i++){
                data.Rows.push(dataList[i]);
                data.total ++ ;
            }
            return data;
        }
        function closeResultWin () {
            $.ligerDialog.hide();
        }
        function renderDate(rowdata, index, value){
            var dateStr = "";
            if(null != value){
                var date = new Date(value);
                dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
            }
            return dateStr;
        }
        function checkCstRisk(sts) {
            if (selectFlag){
                selectFlag = false ;
                return false;
            }
            // if (StringUtils.isEmpty($("#cstId").val())) {
            //     top.$.ligerDialog.SQalert({content: "请选择客户!", SQ_type: "warning"});
            //     return false ;
            // }
            var url = '<%=path%>/project/prjbscinfo/queryCstCreditiInvest.do';
            var params = {
                cstId:$("#cstId").val(),
                prjTypCd:$("#prjTypCd").val()
            };
            var cstTypCd = $("#cstTypCd").val();
            var flag = false;
            if(cstTypCd && params.cstId && params.prjTypCd){
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: params,
                    async : false,
                    url: url,
                    success: function (msg) {
                        if (msg.success == 1) {
                            if (msg.data.rcCstBscInfoMap && msg.data.rcCstBscInfoMap.rcCstBscInfoList){
                                var checkFlag = false;
                                for (var i=0;i<msg.data.rcCstBscInfoMap.rcCstBscInfoList.length;i++){
                                    if (msg.data.rcCstBscInfoMap.rcCstBscInfoList[i].rskLvlCd != 3){
                                        checkFlag = true;
                                        break;
                                    }
                                }
                                if(checkFlag){
                                    if(sts == 0){
                                        var selectid= parent.$("#isBigCstWork").ligerGetComboBoxManager();
                                        if(msg.signature && msg.signature == 1){
                                            $("#isBigCstWorkDiv").show();
                                            selectid.setValue(1);
                                            selectid.setText("是");
                                        }else{
                                            $("#isBigCstWorkDiv").hide();
                                            selectid.setValue(0);
                                            selectid.setText("否");
                                        }
                                    }
                                }else{
                                    $("#cstId").val(null);
                                    $("#cstNm").val(null);
                                    top.$.ligerDialog.SQalert({content: "当前客户无征信或征信不合规，请核实", SQ_type: "warning"});
                                    return false ;
                                }
                                flag = true ;
                            }else{
                                $("#cstId").val(null);
                                $("#cstNm").val(null);
                                top.$.ligerDialog.SQalert({content: "当前客户无征信或征信不合规，请核实", SQ_type: "warning"});
                                return false ;
                            }
                        }else if(msg.success == 0){
                            $("#cstId").val(null);
                            $("#cstNm").val(null);
                            top.$.ligerDialog.SQalert({content: "当前客户无征信或征信不合规，请核实", SQ_type: "warning"});
                            return false ;
                        }else {
                            $("#cstId").val(null);
                            $("#cstNm").val(null);
                            top.$.ligerDialog.SQalert({content:"查询征信失败,请重试", SQ_type: "warning"});
                            return false ;
                        }
                    }
                });
            }else if(!params.cstId){
                top.$.ligerDialog.SQalert({content: "请选择客户", SQ_type: "warning"});
            }
            // 如果是二手车，切换设备列表
            changeTable();
            return flag ;
        }

        //倒计时次数
        var countdownNum = 1;
        //查询筛选结果倒计时
        function countDownFun(countdown) {
            if (countdownNum <= 3) {
                var timer = setInterval(function () {
                    if (countdown < 1) {
                        //清除定时器
                        clearInterval(timer);
                        countdownNum++;
                        showRouteResult();
                    } else {
                        document.getElementById("count_down_span_id").innerText = countdown;
                        countdown--;
                    }
                }, 1000);
            }
        }
        var changeTable = function(){
            if(prjTypCdFlag != getIsSecond($("#prjTypCd").val())){ // 如果是新车和二手车之间切换
                if(getIsSecond($("#prjTypCd").val())){
                    $("#licDtdiv").hide();
                    $("#licAgainDiv").hide();
                    $("#grid_chanpin").hide();
                    $("#addGuacheBtn").hide();
                    $("#copyBtn").hide();
                    $("#isSplMfrDiv").hide();
                    $("#isBpDiv").hide();
                    $("#grid_chanpin").hide();
                    $("#isPreIntDiv").hide();
                    $("#isFarmerDiv").hide();
                    $("#isBigCstWorkDiv").hide();
                    $("#isLicDiv").hide();
                    $("#payWayCdDiv").show();
                    $("#isVisitDiv").show();
                    $("#grid_ershouche").show();
                    ligerGrid_escload(editFlag);
                    for(var i=0;i<ligerGrid_esc.rows.length;i++){
                        ligerGrid_esc.deleteRow(ligerGrid_esc.rows.length-1) ;
                    }
                }else{
                    // $("#licDtdiv").show();
                    $("#licAgainDiv").show();
                    $("#grid_chanpin").show();
                    $("#addGuacheBtn").show();
                    $("#copyBtn").show();
                    $("#isSplMfrDiv").show();
                    $("#isBpDiv").show();
                    $("#isPreIntDiv").show();
                    $("#grid_chanpin").show();
                    $("#payWayCdDiv").hide();
                    $("#isVisitDiv").hide();
                    $("#isFarmerDiv").show();
                    $("#isLicDiv").show();
                    $("#grid_ershouche").hide();
                    ligerGrid_chanpinload(editFlag);
                    for(var i=0;i<ligerGrid_chanpin.rows.length;i++){
                        ligerGrid_chanpin.deleteRow(ligerGrid_chanpin.rows.length-1) ;
                    }
                }
                // 清空报价信息和上牌信息
                if(prjTypCdFlag !== undefined){
                    $("#cstId").val('');
                    $("#cstNm").val('');
                    if(getIsSecond($("#prjTypCd").val())){
                        $("#isFarmer").val('');
                        $("#isBigCstWork").val('');
                        $("#isLic").val('');
                        $("#isLicAgain").val('');
                        $("#isSplMfr").val('');
                        $("#isPreInt").val('');
                        $("#isBp").val('');
                        $("#isVisit").val('0');
                    }else{
                        $("#isFarmer").val('0');
                        $("#isLic").val('0');
                        $("#isLicAgain").val('0');
                        $("#isSplMfr").val('0');
                        $("#isPreInt").val('0');
                        $("#isBp").val('0');
                        $("#isVisit").val('');
                    }
                    $("#rgnProvCd").val('');
                    $("#rgnCityCd").val('');
                    $("#licDt").val('');
                    $("#licAgainDt").val('');
                    $("#contAmt").val(0);
                    $("#lsPd").val('');
                    $("#annIntRatePct").val('');
                }
            }
            if (getIsSecond($("#prjTypCd").val()) && ligerGrid_esc){
                if($("#prjTypCd").val() != 'ESCJYD' && $("#prjTypCd").val() != 'OWNJYD'){
                    ligerGrid_esc.toggleCol('splRgnPrCd', false);
                }else{
                    ligerGrid_esc.toggleCol('splRgnPrCd', true);
                }
                if($("#prjTypCd").val() == 'CDDYWUL'){
                    ligerGrid_esc.toggleCol('lsActAmt', true);
                }else{
                    ligerGrid_esc.toggleCol('lsActAmt', false);
                }
            }
            prjTypCdFlag = getIsSecond($("#prjTypCd").val()) ;
        }

        function  showBigCstWork() {
            var url = '<%=path%>/project/prjbscinfo/queryCstCreditiInvest.do';
            var params = {
                cstId:$("#cstId").val(),
                prjTypCd:$("#prjTypCd").val()
            };
            if(params.cstId && params.prjTypCd){
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: params,
                    async : false,
                    url: url,
                    success: function (msg) {
                        if (msg.success == 1) {
                            if(msg.signature && msg.signature == 1){
                                $("#isBigCstWorkDiv").show();
                            }
                        }
                    }
                });
            }
        }
        var getValue = function(keyValueList,key){
            for(var i=0;i<keyValueList.length;i++){
                if (key == keyValueList[i].key){
                    return keyValueList[i].value;
                }
            }
        }
    </script>
</div>
<div id="preRouteResult" style="display: none">
    <div id="preRouteResult_div"></div>
    <div class="sqPanel_head">
        <div class="posL" style="text-align: center;margin-top: 5px;">
            <span id="saveRouteResult" onclick="closeResultWin()" class="sq-button sq-button-round">确认</span>
        </div>
    </div>
</div>
<div id="preRouteLoading" style="text-align: center;height: 100px;line-height: 100px;background:#F0F0F0;display: none;">
    <div class="sqPanel_head">
        <div class="posL">
            <span>资管机构筛选中，请稍后</span>
            <span id="count_down_span_id">5</span>
            <span>s...</span>
        </div>
    </div>
</div>
<div id="preRouteLoadEnd" style="height: 100px;text-align: center;background:#F0F0F0;display: none;">
    <div class="sqPanel_head">
        <div class="posL" style="line-height: 60px;">
            <span>暂无合规机构，请关闭重新进入该页面</span>
        </div>
        <div class="btnsBox">
            <span id="closeBtn" class="sq-button sq-button-round" onclick="closeResultWin()">关闭</span>
        </div>
    </div>
</div>
</body>
</html>